/**
 * Created by OneDream on 2016/1/6.
 */
var account = localStorage.getItem("account");
var start=0;
var size=10;
if (account != "null") {
    $("#root1").scroll(function(){
        var length=$(".item")[0].offsetHeight*$(".item").length;
       //if($("#root1").scrollTop>(length-45)){
       //    size+=10;
       //}
       //alert(length+"---"+$("#root1").scrollTop()+"++++"+$(window).height());
        if(($("#root1").scrollTop())>=(length-$(window).height())){
            start+=10;
            request(account,start,size);
        }
    });
   request(account,start,size);
}
function request(account,start,size){
    //alert("111");
    $.ajax({
    url: "http://192.168.1.11:8080/WeiXin/getMessageLogs",
    data: {
        "account": account,
        "start": start,
        "size": size,
    },
    async: true,
    dataType: "json",
    success: function (data) {
        if (data.status == 0) {
            requestContact(data.data);
            //alert(data.data.length)
            //alert("�����¼");
        } else {
            alert("请求失败");
        }

    },
    error: function () {
        alert("网络异常");
    }

});}
function requestContact(data){
    $.each(data,function(i,item1){
        var item= $("<div class='item' id=item"+i+start+"></div>");
        $("#root").append(item);
        var left= $("<div class='left'></div>");
        item.append(left);
        var img=$("<img src=''/>");
        left.append(img);
        var middle=$("<div class='middle'></div>");
        item.append(middle);
        var up=$("<div class='up'></div>");
        var down=$("<div class='down'></div>");
        middle.append(up);
        middle.append(down);
        var right=$("<div class='right'></div>");
        item.append(right);
        img.attr("src","image/"+item1.toicon+".jpg");
        up.html(item1.tonickname);
        down.html(item1.message);
        right.html(item1.time);
        //alert($("#item"+i));
        $("#item"+i+start).click(function(){
            window.parent.location.href="chat.html?account="+item1.toaccount+"&nickname="+item1.tonickname+"&toicon="+item1.toicon;
        });
    });

}

